//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
//////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2005 Siemens AG
//
// Version: 1.1.2.5
// Date:    11. Jan. 2006
//////////////////////////////////////////////////////////////////////////////

#ifdef AUXCOM_PORT
#ifdef IOCTL_RIL_GETSERIALPORTHANDLEFORSAP
#ifdef IOCTL_RIL_ENTERSAPMODE
#ifdef IOCTL_RIL_EXITSAPMODE
#define SAP_SUPPORTED
#endif // IOCTL_RIL_EXITSAPMODE
#endif // IOCTL_RIL_ENTERSAPMODE
#endif // IOCTL_RIL_GETSERIALPORTHANDLEFORSAP
#endif // AUXCOM_PORT

#ifdef SAP_SUPPORTED
HRESULT RILDrv_EnterSAPMode(DWORD dwParam, const LPRILENTERSAPMODE lpEnterSapMode);
HRESULT RILDrv_ExitSAPMode(DWORD dwParam, BOOL bForce);
#endif SAP_SUPPORTED

#define SAPBeaconRegKey         TEXT("SAPBeaconPeriod")

#define SAP_CMD_PORT            URC_PORT

#define SAP_ROLE_NONE           0
#define SAP_ROLE_SERVER         1
#define SAP_ROLE_CLIENT         2

#ifdef SAP_SUPPORTED
#define SAP_INLINE_VOID
#define SAP_INLINE_BOOL
#else // SAP_SUPPORTED
#define SAP_INLINE_VOID         { }
#define SAP_INLINE_BOOL         { return TRUE; }
#endif // SAP_SUPPORTED

//
// Handling of Remote SIM Access
//
class CRsaHandling {
public:
  CRsaHandling() SAP_INLINE_VOID;
  ~CRsaHandling() SAP_INLINE_VOID;
  BOOL   Init(CRilHandle* pRilDevice) SAP_INLINE_BOOL;
  BOOL   Deinit(void) SAP_INLINE_BOOL;
  void   ResetStates(void) SAP_INLINE_VOID;
  BOOL   Enter(CRilInstanceHandle* pInstance, BOOL fServer, DWORD dwBeaconPeriod) SAP_INLINE_BOOL;
  BOOL   Exit(CRilInstanceHandle* pInstance, BOOL fForce) SAP_INLINE_BOOL;
  BOOL   WaitForExit(DWORD dwTimeout = INFINITE) SAP_INLINE_BOOL;
  BOOL   ParseNotification(LPCSTR& rszPointer, COM_PORT_TYPE PortType) SAP_INLINE_BOOL;

#ifdef SAP_SUPPORTED

private:
  static HRESULT    ParseResult(LPCSTR szRsp, void*& pBlob, UINT& cbBlob, LPVOID pParam);

  CRilHandle*       m_pRilDevice;
  CRITICAL_SECTION  m_csLock;
  HANDLE            m_hExitEvent;
  DWORD             m_dwSapRole;
  DWORD             m_dwLastSapRole;

#endif // SAP_SUPPORTED

};

